<template>
  <j-modal :title="'财务 - ' + title" :width="width" :visible="visible" :maskClosable="false" :keyboard="false" draggable
    switchFullscreen :okButtonProps="{ class: { 'jee-hidden': disableSubmit } }" @cancel="handleCancel">

    <template slot="footer">

      <!-- <a-button v-if="disableSubmit" key="print" @click="handlePrint" style="margin-right: 48px">打印</a-button> -->
      <a-button @click="handleCancel" :type="action === 'detail' ? 'primary' : ''">{{ action === 'detail' ? '关闭' : '取消' }}</a-button>

      <a-button v-if="!disableSubmit" key="submit" @click="addFinancia" type="primary">提交</a-button>


    </template>
    <financial-form ref="realForm" @ok="submitCallback" :disabled="disableSubmit" />
  </j-modal>
</template>

<script>
import { postAction } from '@/api/manage'
// import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { OrderModalMixin } from '../../common/mixins/OrderModalMixin' // 暂时保留，因为这可能是通用混入
import financialForm from "./financialForm.vue";

export default {
  name: 'FinancialModal',
  mixins: [OrderModalMixin],
  components: { financialForm },

  data() {
    return {
      width: 1300,
    }
  },
  methods: {
    // 添加resetForm方法，转发调用到内部的realForm
    resetForm() {
      if (this.$refs.realForm && typeof this.$refs.realForm.resetForm === 'function') {
        this.$refs.realForm.resetForm();
      }
    },

    addFinancia() {
      console.log('addFinancia');
      this.$refs.realForm.validateForm().then(() => {
        let formData = this.$refs.realForm.getFormData();
        let obj = JSON.parse(JSON.stringify(formData));
        console.log('能正常进入obj', obj);
        
        // 处理日期格式
        if (obj.payDate) {
          obj.payDate = obj.payDate.format('YYYY-MM-DD');
        }
         console.log('能正常进入obj1', obj);
    
          this.confirmLoading = true;
          let httpurl = '/wr/financeOtherPay/add';
            postAction(httpurl, obj).then(res => {
            console.log('财务新增的res', res);
            // this.productOptions = res.result.productList;
            if (res.code == 200) {
              this.$message.success(res.message);
              this.$emit('refreshs');
              this.visible = false
            }
          }).catch((error) => {
            this.$message.error('保存失败: ' + (error.message || '未知错误'));
          }).finally(() => {
            this.confirmLoading = false;
          });
        });
    }
  }
}
</script>

<style scoped></style>
